package com_djm_2025_05_11;

import java.util.Scanner;

/**
 * @author dengjiangming
 * @version 1.1.0
 * @date 2025-05-14
 */
public class Demo5 {
//利用辗转相除法求两个数的最大公因子

    public static int greatestCommonDivisor(int num1,int num2){
        int a = Math.abs(num1);
        int b = Math.abs(num2);

        //辗转相除
        while(b != 0){
            int tmp = b;
            b = a % b ;
            a = tmp;
        }

        return a;
    }
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int num1 = sc.nextInt();
        int num2 = sc.nextInt();

        int maxValue = Integer.max(num1,num2);
        int minValue = Integer.min(num1,num2);

        int result = greatestCommonDivisor(maxValue,minValue);

        System.out.println(result);

    }
}
